package com.github.phoenics.newlives.common.util.wechat;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.XmlUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.github.phoenics.newlives.common.util.CurrencyUtil;
import com.github.phoenics.newlives.common.util.SignUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.Assert;

import java.util.Map;
import java.util.UUID;

/**
 * 微信支付工具
 *
 * @author Phoenics Chow
 * on 2019年11月13日
 */
@Slf4j
public class WxpayUtil {
    //public final static String NORMALKEY_NEW = "5k82641nncde16cq2502s18znmtm680s";
    public final static String WX_API_URL = "https://api.mch.weixin.qq.com/pay/unifiedorder";
    private static final String WECHAT_LOGO = "iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAYAAAD0eNT6AAAABmJLR0QA/wD/AP+gvaeTAAA01klEQVR42u3dP2xbZ5rv8cdBVAxBRV6YBRnAuh7bolIIWNN00tiENBdIoYXu2FsoiODixgJsuBntjuMUo0ZQoy0247mjbQwbkHMLQ0FUrDwrrIoAdyjQbhwr1AIqLNL2ehUgZCFjzZDQFBxAtyCPQsuSeEiec973Pef7AQJbiiy/pEU+v/O8f86RnZ0dAQAAwfKO6gEAAADvEQAAAAigdxs/OHLkiOrxKHdh8dwZETkhImdEpKf+q9Q/d0L1+AAAh3pZ/09EZE1ESvVfXz689GRN9eBUa5z2P/LGBwELABcWzw1JrcD/bf3XM6rHBABw1Vr9v/8QkbWHl56kVQ/IS4ENAPWr+yERuVj/FQCAtIg8EJG037sEgQoAFxbPXZKfC/4J1eMBAGjtpdQDwcNLTxZVD8Zpvg8A9Sv9fxCRSyJyVPV4AABGei0iiyLyR790BnwZAC4snjsqIp9JrfCfUD0eAICvvBSRP4rIVw8vPXmtejDt8lUAuLB47oSITEmt+AMA4LavRGT64aUnL1UPpFW+CAD1FfxTwmI+AIAaaakFgbTqgd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PRCTtlyv9gwQ2AOzVEAj+VkTO1P8DAPjXWv2//5AAFPy9CACHqIeCo1ILBj3ycyg4IUwhAIDuXtb/E6kV+pLUrvBfB63Y7+fAAAAAAIJB63sBAAAAdxAAAAAIoP8Pfs+8R8iHFIsAAAAZdEVYdFNvZnR3YXJlAEFkb2JlIEltYWdlUmVhZHlxyWU8AAAAAElFTkSuQmCC";



    public static Map<String, Object> getOrderForwxpayAll(
            String appid,
            String mchId,
            String normalkey,
            String outTradeNo,
            String totalFee,
            String notifyUrl) {
        ScanConfig scanConfig = new ScanConfig(appid, mchId);
        scanConfig.setNotify_url(notifyUrl);
        //scanConfig.setTrade_type("APP");
        scanConfig.setNonce_str(UUID.randomUUID().toString().replace("-", ""));
        scanConfig.setTotal_fee(CurrencyUtil.StringToLong(totalFee));
        scanConfig.setOut_trade_no(outTradeNo);

        Map<String, Object> map = BeanUtil.beanToMap(scanConfig);
        //map.remove("sign");
        String md5Str=SignUtil.postStrMd5(map, "sign", normalkey);
        map.put("sign", md5Str);
        //map = SignUtil.sign(map, "sign", normalkey);
        String xmlData = XmlUtil.mapToXmlStr(map, "xml");
        //log.info("=====xmlData========={}",xmlData);
        String result = HttpRequest.post(WX_API_URL)
                .contentType("application/xml")
                .body(xmlData, "utf-8")
                .timeout(20000)//超时，毫秒
                .execute().body();
        //log.info("=====result========={}",result);
        Assert.hasText(result,"微信支付返回无效");
        Map<String, Object> resultMap = XmlUtil.xmlToMap(result);
        //log.info("=====result========={}",result);
        //微信支付返回结果处理
        String success="";
        Object returnCodeObj = resultMap.get("return_code");
        Object resultCodeObj = resultMap.get("result_code");
        boolean returnCodeObjBool=isNotEmptyorNull(returnCodeObj);
        boolean resultCodeObjBool=isNotEmptyorNull(resultCodeObj);
        //boolean rt=!returnCodeObjBool || !returnCodeObjBool;
        if(returnCodeObjBool){
            success=returnCodeObj.toString().toLowerCase();
        }
        if(resultCodeObjBool){
            success=resultCodeObj.toString().toLowerCase();
        }
        Assert.isTrue(success.equals("success") ,"微信支付返回无效");
        return resultMap;
    }
    public static String getOrderForwxpay(
            String appid,
            String mchId,
            String normalkey,
            String outTradeNo,
            String totalFee,
            String notifyUrl
    ) {
        //log.info("==========111====");
        Map<String, Object> resultMap = getOrderForwxpayAll(appid,mchId,normalkey,outTradeNo, totalFee, notifyUrl);
        //log.info("==========222====");
        WxpayAppConfig appConfig = new WxpayAppConfig();
        appConfig.setAppid(resultMap.get("appid").toString());
        appConfig.setNoncestr(resultMap.get("nonce_str").toString());
        appConfig.setPartnerid(resultMap.get("mch_id").toString());
        appConfig.setPrepayid(resultMap.get("prepay_id").toString());
        appConfig.setTimestamp(String.valueOf(System.currentTimeMillis() / 1000L));
        appConfig = sign(appConfig, normalkey);
        JSONObject jsonObject=JSONUtil.parseObj(appConfig);
        jsonObject.remove("packageName");
        jsonObject.put("package",appConfig.getPackageName());
        //log.info(JSONUtil.toJsonStr(jsonObject.toString()));
        return jsonObject.toString();

    }
    public static WxpayAppConfig sign(WxpayAppConfig config, String key) {
        //first
        String stringA = "appid=" + config.getAppid()
                + "&noncestr=" + config.getNoncestr()
                + "&package=" + config.getPackageName()
                + "&partnerid=" + config.getPartnerid()
                + "&prepayid=" + config.getPrepayid()
                + "&timestamp=" + config.getTimestamp();
        //second
        String stringSignTemp = stringA + "&key=" + key;
        String signValue = SecureUtil.md5(stringSignTemp);
        config.setSign(signValue);
        return config;
    }


    private static boolean isNotEmptyorNull(Object obj) {
        if (obj == null) {
            return false;
        } else if (obj instanceof String) {
            if (obj.toString().trim().equals("") || obj.toString().trim().equals("null")) {
                return false;
            } else {
                return true;
            }
        } else {
            return true;
        }
    }
}
